import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class Test extends Component {
  static propTypes = {
    // 校验规则，规定 colors 必须是一个数组
    colors: PropTypes.array,
    fn: PropTypes.func,
    obj: PropTypes.object.isRequired,
    obj2: PropTypes.shape({
      name: PropTypes.string,
      age: PropTypes.number
    })
  }
  render () {
    // const {obj} = this.props
    // !更建议用 ES6 的特性来实现
    const { age = 18 } = this.props
    return (
      <div>
        {this.props.colors.map(item => (
          <li key={item}>{item}</li>
        ))}
        {/* <div>age:{obj.age}</div> */}
        <div>age:{age}</div>
      </div>
    )
  }
}
// Test.propTypes = {
//   colors: PropTypes.array
// }
// export default Test
